<!DOCTYPE html>
<html lang=zh>
<head><meta name="generator" content="Hexo 3.9.0">
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="description" content="前言今天在逛 segmentfault 的时候，看到人家源码里面各种使用 call, apply。都搞得我看不懂了，于是下定决心搞懂它们的用法。 为什么要使用 call 和 apply观摩大神解释， 知乎文章:在 javascript 面向对象编程中中，我们经常会这样定义: 123456789function cat() &amp;#123;&amp;#125;cat.prototype = &amp;#123;  fo">
<meta name="keywords" content="javascript">
<meta property="og:type" content="article">
<meta property="og:title" content="理解js中的call、apply以及bind">
<meta property="og:url" content="https://andyliwr.github.io/2018/01/12/js_call_apply/index.html">
<meta property="og:site_name" content="月光倾城的代码小屋">
<meta property="og:description" content="前言今天在逛 segmentfault 的时候，看到人家源码里面各种使用 call, apply。都搞得我看不懂了，于是下定决心搞懂它们的用法。 为什么要使用 call 和 apply观摩大神解释， 知乎文章:在 javascript 面向对象编程中中，我们经常会这样定义: 123456789function cat() &amp;#123;&amp;#125;cat.prototype = &amp;#123;  fo">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://file.lantingshucheng.com/blog/2018_01_12/mockapi.png">
<meta property="og:updated_time" content="2020-01-15T06:30:09.116Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="理解js中的call、apply以及bind">
<meta name="twitter:description" content="前言今天在逛 segmentfault 的时候，看到人家源码里面各种使用 call, apply。都搞得我看不懂了，于是下定决心搞懂它们的用法。 为什么要使用 call 和 apply观摩大神解释， 知乎文章:在 javascript 面向对象编程中中，我们经常会这样定义: 123456789function cat() &amp;#123;&amp;#125;cat.prototype = &amp;#123;  fo">
<meta name="twitter:image" content="https://file.lantingshucheng.com/blog/2018_01_12/mockapi.png">
    
    
        
          
              <link rel="shortcut icon" href="/images/favicon.ico">
          
        
        
          
            <link rel="icon" type="image/png" href="/images/favicon-192x192.png" sizes="192x192">
          
        
        
          
            <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
          
        
    
    <!-- title -->
    <title>理解js中的call、apply以及bind</title>
    <!-- styles -->
    <link rel="stylesheet" href="/css/style.css">
    <!-- persian styles -->
    
      <link rel="stylesheet" href="/css/rtl.css">
    
    <!-- rss -->
    
    
</head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" href="/2018/02/12/vue_multiple_pages_develop/"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" href="/2018/01/12/linux_ssh_proxy/"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">上一篇</span>
      <span id="i-next" class="info" style="display:none;">下一篇</span>
      <span id="i-top" class="info" style="display:none;">返回顶部</span>
      <span id="i-share" class="info" style="display:none;">分享文章</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://andyliwr.github.io/2018/01/12/js_call_apply/"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://andyliwr.github.io/2018/01/12/js_call_apply/&text=理解js中的call、apply以及bind"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://andyliwr.github.io/2018/01/12/js_call_apply/&title=理解js中的call、apply以及bind"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://andyliwr.github.io/2018/01/12/js_call_apply/&is_video=false&description=理解js中的call、apply以及bind"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=理解js中的call、apply以及bind&body=Check out this article: https://andyliwr.github.io/2018/01/12/js_call_apply/"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://andyliwr.github.io/2018/01/12/js_call_apply/&title=理解js中的call、apply以及bind"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://andyliwr.github.io/2018/01/12/js_call_apply/&title=理解js中的call、apply以及bind"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://andyliwr.github.io/2018/01/12/js_call_apply/&title=理解js中的call、apply以及bind"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://andyliwr.github.io/2018/01/12/js_call_apply/&title=理解js中的call、apply以及bind"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://andyliwr.github.io/2018/01/12/js_call_apply/&name=理解js中的call、apply以及bind&description="><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#前言"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#为什么要使用-call-和-apply"><span class="toc-number">2.</span> <span class="toc-text">为什么要使用 call 和 apply</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#为什么我一直对-call-和-apply-感到这么陌生"><span class="toc-number">3.</span> <span class="toc-text">为什么我一直对 call 和 apply 感到这么陌生</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#call-和-apply-的用例"><span class="toc-number">4.</span> <span class="toc-text">call 和 apply 的用例</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#bind"><span class="toc-number">5.</span> <span class="toc-text">bind</span></a></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        理解js中的call、apply以及bind
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">月光倾城的代码小屋</span>
      </span>
      
    <div class="postdate">
        <time datetime="2018-01-12T16:30:54.000Z" itemprop="datePublished">2018-01-12</time>
    </div>


      

      
    <div class="article-tag">
        <i class="fas fa-tag"></i>
        <a class="tag-link" href="/tags/javascript/">javascript</a>
    </div>


    </div>
  </header>
  

  <div class="content" itemprop="articleBody">
    <h4 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h4><p>今天在逛 segmentfault 的时候，看到人家源码里面各种使用 call, apply。都搞得我看不懂了，于是下定决心搞懂它们的用法。</p>
<h4 id="为什么要使用-call-和-apply"><a href="#为什么要使用-call-和-apply" class="headerlink" title="为什么要使用 call 和 apply"></a>为什么要使用 call 和 apply</h4><p>观摩大神解释， <a href="https://www.zhihu.com/question/20289071" target="_blank" rel="noopener">知乎文章</a>:<br>在 javascript 面向对象编程中中，我们经常会这样定义:</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">cat</span>(<span class="params"></span>) </span>&#123;&#125;</span><br><span class="line">cat.prototype = &#123;</span><br><span class="line">  food: <span class="string">'fish'</span>,</span><br><span class="line">  say: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    alert(<span class="string">'I love '</span> + <span class="keyword">this</span>.food);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">var</span> blackCat = <span class="keyword">new</span> cat();</span><br><span class="line">blackCat.say();</span><br></pre></td></tr></table></figure>
<p>但是如果我们有一个对象<code>whiteDog = {food:&quot;bone&quot;}</code>,我们不想对它重新定义<code>say</code>方法，那么我们可以通过 call 或 apply 用<code>blackCat</code>的<code>say</code>方法：<code>blackCat.say.call(whiteDog);</code></p>
<p>所以，可以看出 call 和 apply 是为了动态改变 this 而出现的，当一个 object 没有某个方法，但是其他的有，我们可以借助 call 或 apply 用其它对象的方法来操作。用的比较多的，通过<code>document.getElementsByTagName</code>选择的 dom 节点是一种类似<code>array</code>的<code>array</code>。它不能应用<code>Array</code>下的 push,pop 等方法。我们可以通过：<code>var domNodes = Array.prototype.slice.call(document.getElementsByTagName(&quot;*&quot;));</code>这样 domNodes 就可以应用<code>Array</code>下的所有方法了。</p>
<p>call 和 apply 都是为了改变某个函数运行时的 context 即上下文而存在的，换句话说，就是为了改变函数体内部 this 的指向。因为 JavaScript 的函数存在「定义时上下文」和「运行时上下文」以及「上下文是可以改变的」这样的概念。</p>
<p>二者的作用完全一样，只是接受参数的方式不太一样。例如，有一个函数 func1 定义如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> func1 = <span class="function"><span class="keyword">function</span>(<span class="params">arg1, arg2</span>) </span>&#123;&#125;;</span><br></pre></td></tr></table></figure>
<p>就可以通过<code>func1.call(this, arg1, arg2);</code>或者<code>func1.apply(this, [arg1, arg2]);</code>来调用。其中<code>this</code>是你想指定的上下文，他可以任何一个 javascript 对象(javascript 中一切皆对象)，call 需要把参数按顺序传递进去，而 apply 则是把参数放在数组里。</p>
<p>javascript 中，某个函数的参数数量是不固定的，因此要说适用条件的话，当你的参数是明确知道数量时，用 call，而不确定的时候，用 apply，然后把参数 push 进数组传递进去。当参数数量不确定时，函数内部也可以通过<code>arguments</code>这个数组来便利所有的参数。</p>
<h4 id="为什么我一直对-call-和-apply-感到这么陌生"><a href="#为什么我一直对-call-和-apply-感到这么陌生" class="headerlink" title="为什么我一直对 call 和 apply 感到这么陌生"></a>为什么我一直对 call 和 apply 感到这么陌生</h4><p>因为在平时的工作中我遇到的几乎都是流程式的代码，很少涉及到对象编程。比如一段代码重复使用，我们就可以定义一个全局函数来复用代码。这样一直在使用全局(windows)来调用这个函数，根本就不会用到 call 或者 apply 去改变上下文。再比如我们在一个对象中定义对象的方法，基本上也不会涉及到其他对象需要调用这个对象的方法的场景。至于用 call 和 apply 实现继承就更别谈了。</p>
<p>看看以前的 sb 做法：<br><img src="https://file.lantingshucheng.com/blog/2018_01_12/mockapi.png" alt></p>
<h4 id="call-和-apply-的用例"><a href="#call-和-apply-的用例" class="headerlink" title="call 和 apply 的用例"></a>call 和 apply 的用例</h4><ol>
<li><strong>实现继承</strong></li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> Parent = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    <span class="keyword">this</span>.name = <span class="string">"yjc"</span></span><br><span class="line">    <span class="keyword">this</span>.age = <span class="number">22</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> child = &#123;&#125;</span><br><span class="line"><span class="built_in">console</span>.log(child);<span class="comment">//Object &#123;&#125; ,空对象</span></span><br><span class="line">Parent.call(child) <span class="comment">// Parent也是一个方法，意思就是让child拥有Parant方法的上下文，拥有Parent的属性，因为Parent不需要参数，所以call除了传一个child也没传别的</span></span><br><span class="line"><span class="built_in">console</span>.log(child) <span class="comment">//Object &#123;name: "yjc", age: 22&#125;</span></span><br></pre></td></tr></table></figure>
<ol start="2">
<li><p><strong>柯里化和反柯里化</strong></p>
<p><strong>柯里化</strong><br>在计算机科学中，柯里化（英语：<code>Currying</code>），又译为卡瑞化或加里化，是把接受多个参数的函数变换成接受一个单一参数（最初函数的第一个参数）的函数，并且返回接受余下的参数而且返回结果的新函数的技术。 – 维基百科</p>
</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> curry = <span class="function"><span class="keyword">function</span>(<span class="params">fn</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">var</span> _args = [];</span><br><span class="line"></span><br><span class="line">  <span class="keyword">return</span> <span class="function"><span class="keyword">function</span> <span class="title">_f</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (<span class="built_in">arguments</span>.length) &#123;</span><br><span class="line">      <span class="comment">// 合并参数好像只能通过这种方式实现，如果直接是_args.push(arguments)的到的是“0[object Arguments][object Arguments]”</span></span><br><span class="line">      <span class="comment">// 这里猜测Array.prototype.push.apply能够过滤掉参数自带的默认属性</span></span><br><span class="line">      <span class="built_in">Array</span>.prototype.push.apply(_args, <span class="built_in">arguments</span>);</span><br><span class="line">      <span class="keyword">return</span> _f;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> fn.apply(<span class="keyword">this</span>, _args);</span><br><span class="line">  &#125;;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 累加方法</span></span><br><span class="line"><span class="keyword">var</span> add = curry(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="built_in">Array</span>.prototype.reduce.call(</span><br><span class="line">    <span class="built_in">arguments</span>,</span><br><span class="line">    <span class="function"><span class="keyword">function</span>(<span class="params">acc, cur</span>) </span>&#123;</span><br><span class="line">      <span class="keyword">return</span> acc + cur;</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="number">0</span></span><br><span class="line">  );</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">add(<span class="number">1</span>)(<span class="number">2</span>)(<span class="number">3</span>)(); <span class="comment">// 6</span></span><br><span class="line">add(<span class="number">4</span>)(); <span class="comment">// 10</span></span><br></pre></td></tr></table></figure>
<p>感觉柯里化的原理就那样，就是在你传一个或者多个参数的时候，将参数合并到闭包变量_args，直到参数为空，才将累计的参数传给最终的执行函数</p>
<p><strong>反柯里化</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">Function</span>.prototype.uncurry = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="keyword">var</span> _this = <span class="keyword">this</span>;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">return</span> <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="built_in">Function</span>.prototype.call.apply(_this, <span class="built_in">arguments</span>);</span><br><span class="line">  &#125;;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> obj = &#123;&#125;;</span><br><span class="line"><span class="keyword">var</span> arr = [];</span><br><span class="line"><span class="keyword">var</span> push = <span class="built_in">Array</span>.prototype.push.uncurry();</span><br><span class="line"></span><br><span class="line">push(obj, <span class="string">'hello'</span>, <span class="string">'world'</span>); <span class="comment">// obj &#123;0: "hello", 1: "world", length: 2&#125;</span></span><br><span class="line">push(arr, <span class="string">'hello'</span>, <span class="string">'world'</span>); <span class="comment">// arr ["hello", "world"]</span></span><br></pre></td></tr></table></figure>
<p>反 curring 就是把原来已经固定的参数或者 this 上下文等当作参数延迟到未来传递。</p>
<h4 id="bind"><a href="#bind" class="headerlink" title="bind"></a>bind</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">obj.bind(thisObj, arg1, arg2, ...);</span><br></pre></td></tr></table></figure>
<p>把 obj 绑定到 thisObj，这时候 thisObj 具备了 obj 的属性和方法。与 call 和 apply 不同的是，bind 绑定后不会立即执行。</p>
<p>同样是 add()和 sub()：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">add.bind(sub, <span class="number">5</span>, <span class="number">3</span>); <span class="comment">//不再返回8</span></span><br><span class="line">add.bind(sub, <span class="number">5</span>, <span class="number">3</span>)(); <span class="comment">//8</span></span><br></pre></td></tr></table></figure>
<p>如果 bind 的第一个参数是 null 或者 undefined，等于将 this 绑定到全局对象。</p>

  </div>
  <div class="statement">
    <hr>  
    1. 如果本文帮到了您，不妨点一下右上角的”<i class="fas fa-share-alt"></i>“按钮。<br>
    2. 除非注明，本博文章均为原创，转载请以链接形式标明本文地址。<br>
    3. 如果你有任何疑问，欢迎发送邮件到我的邮箱<a href="mailto:andyliwr@outlook.com">andyliwr@outlook.com<br>
  </div>
</article>


    <div class="blog-post-comments">
        <div id="gitalk_thread">
            <noscript>加载评论需要在浏览器启用 JavaScript 脚本支持。</noscript>
        </div>
    </div>



        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#前言"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#为什么要使用-call-和-apply"><span class="toc-number">2.</span> <span class="toc-text">为什么要使用 call 和 apply</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#为什么我一直对-call-和-apply-感到这么陌生"><span class="toc-number">3.</span> <span class="toc-text">为什么我一直对 call 和 apply 感到这么陌生</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#call-和-apply-的用例"><span class="toc-number">4.</span> <span class="toc-text">call 和 apply 的用例</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#bind"><span class="toc-number">5.</span> <span class="toc-text">bind</span></a></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://andyliwr.github.io/2018/01/12/js_call_apply/"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://andyliwr.github.io/2018/01/12/js_call_apply/&text=理解js中的call、apply以及bind"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://andyliwr.github.io/2018/01/12/js_call_apply/&title=理解js中的call、apply以及bind"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://andyliwr.github.io/2018/01/12/js_call_apply/&is_video=false&description=理解js中的call、apply以及bind"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=理解js中的call、apply以及bind&body=Check out this article: https://andyliwr.github.io/2018/01/12/js_call_apply/"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://andyliwr.github.io/2018/01/12/js_call_apply/&title=理解js中的call、apply以及bind"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://andyliwr.github.io/2018/01/12/js_call_apply/&title=理解js中的call、apply以及bind"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://andyliwr.github.io/2018/01/12/js_call_apply/&title=理解js中的call、apply以及bind"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://andyliwr.github.io/2018/01/12/js_call_apply/&title=理解js中的call、apply以及bind"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://andyliwr.github.io/2018/01/12/js_call_apply/&name=理解js中的call、apply以及bind&description="><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> 菜单</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> 目录</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> 分享</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> 返回顶部</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy; 2020 Dikang Li
  </div>
  <div class="footer-right">
    <nav>
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </nav>
  </div>
</footer>

    </div>
</body>
</html>
<!-- styles -->
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
<link rel="stylesheet" href="/lib/justified-gallery/css/justifiedGallery.min.css">
<link rel="stylesheet" href="/lib/fancybox/jquery.fancybox.css">

<link rel="stylesheet" href="https://file.lantingshucheng.com/blog/v3/static/styles/gitalk.css">


<!-- jquery -->
<script src="/lib/jquery/jquery.min.js"></script>
<script src="/lib/justified-gallery/js/jquery.justifiedGallery.min.js"></script>
<script src="/lib/fancybox/jquery.fancybox.pack.js"></script>

<script type="text/javascript" src="https://file.lantingshucheng.com/blog/v3/static/scripts/md5.js"></script>
<script type="text/javascript" src="https://file.lantingshucheng.com/blog/v3/static/scripts/gitalk.min.js"></script>

<script src="/js/main.js"></script>
<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

    <script type="text/javascript">
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?7851ca7a86be957be994acb77639a5be";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>

<!-- Disqus Comments -->


  <script type="text/javascript">
    window.onload = function(){
      if (window.location.href.indexOf('andyliwr.github.io') > -1) {
        var gitalk = new Gitalk({
          clientID: 'ad6f70df0c70d2b715f9',
          clientSecret: '40384bee244c1e17dd7c37733d21e9ef669e969c',
          repo: 'Andyliwr.github.io',
          owner: 'Andyliwr',
          admin: ['Andyliwr'],
          id: md5(location.pathname),
          distractionFreeMode: 'true'
        })
        gitalk.render('gitalk_thread')
      }
    }
  </script>


